/*
 * Copyright (c) 2017. 深圳掌控网络有限公司. All rights reserved.
 */

package com.yiqi.lottery.feature.mine.presenter;

import android.text.TextUtils;
import com.alibaba.fastjson.JSON;
import com.qiniu.android.common.FixedZone;
import com.qiniu.android.http.ResponseInfo;
import com.qiniu.android.storage.*;
import com.suozhang.framework.entity.bo.PageData;
import com.suozhang.framework.entity.bo.UserInfoBo;
import com.suozhang.framework.utils.T;
import com.suozhang.framework.utils.ValidatorUtil;
import com.suozhang.framework.utils.logger.Logger;
import com.yiqi.lottery.entity.bo.*;
import com.yiqi.lottery.feature.lottery.dependencies.order.DaggerOrderPresenterComponent;
import com.yiqi.lottery.feature.mine.contract.MineContract;
import com.yiqi.lottery.feature.mine.contract.OrderContract;
import com.yiqi.lottery.feature.mine.dependencies.mine.DaggerMinePresenterComponent;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import org.json.JSONObject;

import javax.inject.Inject;
import java.io.File;

/**
 *      LIJUWEN
 * @email yiyayiyayaoljw@gmail.com
 * @date 2017/4/11 9:31
 */
public class OrderPresenter implements OrderContract.Presenter {

    private OrderContract.View mView;

    @Inject

    OrderContract.Model mModel;


    public OrderPresenter(OrderContract.View mView) {
        this.mView = mView;
        DaggerOrderPresenterComponent.create().inject(this);
    }


    @Override
    public void getOrderList(int page,int type) {
        mModel.getOrderList(page,type).compose(mView.bindToLife()).subscribe(new Observer<PageData<OrderListBo>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(PageData<OrderListBo> s) {
                mView.dismissLoading();

                if (s.getList().size() > 0) {
                    mView.showOrderListSuccess(s);
                } else {
                    mView.showOrderListEmpty();
                }
            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showOrderListError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }

    @Override
    public void getOrderMoreList(int page,int type) {
        mModel.getOrderList(page,type).compose(mView.bindToLife()).subscribe(new Observer<PageData<OrderListBo>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(PageData<OrderListBo> s) {
             mView.showOrderListMoreSuccess(s);
            }

            @Override
            public void onError(Throwable e) {
              mView.showOrderListMoreError(e.getMessage());
            }

            @Override
            public void onComplete() {
            }
        });
    }

    @Override
    public void getMyCopurceOrderList(int page) {
        mModel.getMyCopurceOrderList(page).compose(mView.bindToLife()).subscribe(new Observer<PageData<OrderListBo>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(PageData<OrderListBo> s) {
                mView.dismissLoading();

                if (s.getList().size() > 0) {
                    mView.showOrderListSuccess(s);
                } else {
                    mView.showOrderListEmpty();
                }
            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showOrderListError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }

    @Override
    public void getMyCopurceOrdeMorerList(int page) {
        mModel.getMyCopurceOrderList(page).compose(mView.bindToLife()).subscribe(new Observer<PageData<OrderListBo>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(PageData<OrderListBo> s) {
                mView.showOrderListMoreSuccess(s);
            }

            @Override
            public void onError(Throwable e) {
                mView.showOrderListMoreError(e.getMessage());
            }

            @Override
            public void onComplete() {
            }
        });
    }

    @Override
    public void start() {

    }

}
